package com.kyzh.core.pager.weal.coupon

import android.graphics.Color
import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.beans.GoldDetail
import com.gushenge.core.requests.UserRequest
import com.kyzh.core.R
import kotlinx.android.synthetic.main.activity_zjls.*

class ZJLSActivity : BaseActivity() {
    private val beans = arrayListOf<GoldDetail>()
    private val adapter = Adapter(R.layout.item_sharehistory,beans)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_zjls)
        rvHistory.adapter = adapter

        beans.add(0, GoldDetail(getString(R.string.gold),getString(R.string.reward),getString(R.string.time)))
        adapter.notifyDataSetChanged()
        initData()
    }

    private fun initData() {
        UserRequest.Zhongjiang(this){
            beans.addAll(it)
            adapter.notifyDataSetChanged()
        }
    }


    private inner class Adapter(layout:Int,beans:ArrayList<GoldDetail>): BaseQuickAdapter<GoldDetail, BaseViewHolder>(layout,beans){
        override fun convert(helper: BaseViewHolder, item: GoldDetail) {
            helper.setText(R.id.tv1,item.time)
                    .setText(R.id.tv2,item.note)
                    .setText(R.id.tv3,item.gold)

            if (helper.layoutPosition==0){
                helper.setBackgroundColor(R.id.tv1, Color.parseColor("#E9F1FF"))
                        .setBackgroundColor(R.id.tv2, Color.parseColor("#E9F1FF"))
                        .setBackgroundColor(R.id.tv3, Color.parseColor("#E9F1FF"))
            }else{
                helper.setBackgroundColor(R.id.tv1, Color.WHITE)
                        .setBackgroundColor(R.id.tv2, Color.WHITE)
                        .setBackgroundColor(R.id.tv3, Color.WHITE)
            }
        }
    }
}